﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace AnQinFrameWorkAPI.Migrations
{
    /// <inheritdoc />
    public partial class _20259281544 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "IsDelete",
                table: "Staff");

            migrationBuilder.DropColumn(
                name: "IsDelete",
                table: "Department");

            migrationBuilder.AlterColumn<string>(
                name: "CustomerId",
                table: "ProjectList",
                type: "nvarchar(36)",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(50)",
                oldMaxLength: 50,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "CreateStaffId",
                table: "ProjectList",
                type: "nvarchar(36)",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CreateStaffName",
                table: "ProjectList",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomerName",
                table: "ProjectList",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "ProjectListId",
                table: "ProjectDemand",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldMaxLength: 50,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "ImplementStaffId",
                table: "ProjectDemand",
                type: "nvarchar(36)",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "DevelopStaffId",
                table: "ProjectDemand",
                type: "nvarchar(36)",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "CreateStaffId",
                table: "ProjectDemand",
                type: "nvarchar(36)",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CreateStaffName",
                table: "ProjectDemand",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "DevelopStaffName",
                table: "ProjectDemand",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "ImplementStaffName",
                table: "ProjectDemand",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "CreateStaffId",
                table: "ProjectCustomer",
                type: "nvarchar(36)",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CreateStaffName",
                table: "ProjectCustomer",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "MenuId",
                table: "Menu",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "SaleStaffId",
                table: "DevelopProjectManager",
                type: "nvarchar(36)",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "ProjectId",
                table: "DevelopProjectManager",
                type: "nvarchar(36)",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "CreateStaffId",
                table: "DevelopProjectManager",
                type: "nvarchar(36)",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CreateStaffName",
                table: "DevelopProjectManager",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "ProjectCode",
                table: "DevelopProjectManager",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "ProjectName",
                table: "DevelopProjectManager",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "SaleStaffName",
                table: "DevelopProjectManager",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_StaffRole_StaffId",
                table: "StaffRole",
                column: "StaffId");

            migrationBuilder.CreateIndex(
                name: "IX_Staff_DepartmentId",
                table: "Staff",
                column: "DepartmentId");

            migrationBuilder.CreateIndex(
                name: "IX_RoleMenu_MenuId",
                table: "RoleMenu",
                column: "MenuId");

            migrationBuilder.CreateIndex(
                name: "IX_RoleField_MenuFieldId",
                table: "RoleField",
                column: "MenuFieldId");

            migrationBuilder.CreateIndex(
                name: "IX_RoleButton_MenuButtonId",
                table: "RoleButton",
                column: "MenuButtonId");

            migrationBuilder.CreateIndex(
                name: "IX_MenuField_MenuId",
                table: "MenuField",
                column: "MenuId");

            migrationBuilder.CreateIndex(
                name: "IX_MenuButton_MenuId",
                table: "MenuButton",
                column: "MenuId");

            migrationBuilder.CreateIndex(
                name: "IX_Menu_MenuId",
                table: "Menu",
                column: "MenuId");

            migrationBuilder.CreateIndex(
                name: "IX_Department_SuperiorId",
                table: "Department",
                column: "SuperiorId",
                unique: true,
                filter: "[SuperiorId] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_CodeRuleItem_CodeRuleId",
                table: "CodeRuleItem",
                column: "CodeRuleId");

            migrationBuilder.AddForeignKey(
                name: "FK_CodeRuleItem_CodeRule_CodeRuleId",
                table: "CodeRuleItem",
                column: "CodeRuleId",
                principalTable: "CodeRule",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Department_Department_SuperiorId",
                table: "Department",
                column: "SuperiorId",
                principalTable: "Department",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Menu_Menu_MenuId",
                table: "Menu",
                column: "MenuId",
                principalTable: "Menu",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_MenuButton_Menu_MenuId",
                table: "MenuButton",
                column: "MenuId",
                principalTable: "Menu",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_MenuField_Menu_MenuId",
                table: "MenuField",
                column: "MenuId",
                principalTable: "Menu",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_RoleButton_MenuButton_MenuButtonId",
                table: "RoleButton",
                column: "MenuButtonId",
                principalTable: "MenuButton",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_RoleField_MenuField_MenuFieldId",
                table: "RoleField",
                column: "MenuFieldId",
                principalTable: "MenuField",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_RoleMenu_Menu_MenuId",
                table: "RoleMenu",
                column: "MenuId",
                principalTable: "Menu",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Staff_Department_DepartmentId",
                table: "Staff",
                column: "DepartmentId",
                principalTable: "Department",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_StaffRole_Staff_StaffId",
                table: "StaffRole",
                column: "StaffId",
                principalTable: "Staff",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_CodeRuleItem_CodeRule_CodeRuleId",
                table: "CodeRuleItem");

            migrationBuilder.DropForeignKey(
                name: "FK_Department_Department_SuperiorId",
                table: "Department");

            migrationBuilder.DropForeignKey(
                name: "FK_Menu_Menu_MenuId",
                table: "Menu");

            migrationBuilder.DropForeignKey(
                name: "FK_MenuButton_Menu_MenuId",
                table: "MenuButton");

            migrationBuilder.DropForeignKey(
                name: "FK_MenuField_Menu_MenuId",
                table: "MenuField");

            migrationBuilder.DropForeignKey(
                name: "FK_RoleButton_MenuButton_MenuButtonId",
                table: "RoleButton");

            migrationBuilder.DropForeignKey(
                name: "FK_RoleField_MenuField_MenuFieldId",
                table: "RoleField");

            migrationBuilder.DropForeignKey(
                name: "FK_RoleMenu_Menu_MenuId",
                table: "RoleMenu");

            migrationBuilder.DropForeignKey(
                name: "FK_Staff_Department_DepartmentId",
                table: "Staff");

            migrationBuilder.DropForeignKey(
                name: "FK_StaffRole_Staff_StaffId",
                table: "StaffRole");

            migrationBuilder.DropIndex(
                name: "IX_StaffRole_StaffId",
                table: "StaffRole");

            migrationBuilder.DropIndex(
                name: "IX_Staff_DepartmentId",
                table: "Staff");

            migrationBuilder.DropIndex(
                name: "IX_RoleMenu_MenuId",
                table: "RoleMenu");

            migrationBuilder.DropIndex(
                name: "IX_RoleField_MenuFieldId",
                table: "RoleField");

            migrationBuilder.DropIndex(
                name: "IX_RoleButton_MenuButtonId",
                table: "RoleButton");

            migrationBuilder.DropIndex(
                name: "IX_MenuField_MenuId",
                table: "MenuField");

            migrationBuilder.DropIndex(
                name: "IX_MenuButton_MenuId",
                table: "MenuButton");

            migrationBuilder.DropIndex(
                name: "IX_Menu_MenuId",
                table: "Menu");

            migrationBuilder.DropIndex(
                name: "IX_Department_SuperiorId",
                table: "Department");

            migrationBuilder.DropIndex(
                name: "IX_CodeRuleItem_CodeRuleId",
                table: "CodeRuleItem");

            migrationBuilder.DropColumn(
                name: "CreateStaffName",
                table: "ProjectList");

            migrationBuilder.DropColumn(
                name: "CustomerName",
                table: "ProjectList");

            migrationBuilder.DropColumn(
                name: "CreateStaffName",
                table: "ProjectDemand");

            migrationBuilder.DropColumn(
                name: "DevelopStaffName",
                table: "ProjectDemand");

            migrationBuilder.DropColumn(
                name: "ImplementStaffName",
                table: "ProjectDemand");

            migrationBuilder.DropColumn(
                name: "CreateStaffName",
                table: "ProjectCustomer");

            migrationBuilder.DropColumn(
                name: "MenuId",
                table: "Menu");

            migrationBuilder.DropColumn(
                name: "CreateStaffName",
                table: "DevelopProjectManager");

            migrationBuilder.DropColumn(
                name: "ProjectCode",
                table: "DevelopProjectManager");

            migrationBuilder.DropColumn(
                name: "ProjectName",
                table: "DevelopProjectManager");

            migrationBuilder.DropColumn(
                name: "SaleStaffName",
                table: "DevelopProjectManager");

            migrationBuilder.AddColumn<bool>(
                name: "IsDelete",
                table: "Staff",
                type: "bit",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AlterColumn<string>(
                name: "CustomerId",
                table: "ProjectList",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(36)",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "CreateStaffId",
                table: "ProjectList",
                type: "uniqueidentifier",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(36)",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "ProjectListId",
                table: "ProjectDemand",
                type: "uniqueidentifier",
                maxLength: 50,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(50)",
                oldMaxLength: 50,
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "ImplementStaffId",
                table: "ProjectDemand",
                type: "uniqueidentifier",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(36)",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "DevelopStaffId",
                table: "ProjectDemand",
                type: "uniqueidentifier",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(36)",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "CreateStaffId",
                table: "ProjectDemand",
                type: "uniqueidentifier",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(36)",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "CreateStaffId",
                table: "ProjectCustomer",
                type: "uniqueidentifier",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(36)",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "SaleStaffId",
                table: "DevelopProjectManager",
                type: "uniqueidentifier",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(36)",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "ProjectId",
                table: "DevelopProjectManager",
                type: "uniqueidentifier",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(36)",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "CreateStaffId",
                table: "DevelopProjectManager",
                type: "uniqueidentifier",
                maxLength: 36,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(36)",
                oldMaxLength: 36,
                oldNullable: true);

            migrationBuilder.AddColumn<bool>(
                name: "IsDelete",
                table: "Department",
                type: "bit",
                nullable: false,
                defaultValue: false);
        }
    }
}
